package com.longcai.piaojia.adapter;

import android.content.Context;
import android.net.Uri;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.longcai.piaojia.R;
import com.longcai.piaojia.conn.ShowTypeListGet;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by Administrator on 2016/9/27.
 */
public class RushedAdapter2 extends RecyclerView.Adapter<RushedAdapter2.RushedHolder> {

    private Context context;
    private List<ShowTypeListGet.ShowTypeEntity> list = new ArrayList<>();

    public OnItemClickListener onItemClickListener;
    public HashMap<Integer, Boolean> tabChooseMap;

    public RushedAdapter2(Context context, List<ShowTypeListGet.ShowTypeEntity> list) {
        this.context = context;
        this.list = list;
        tabChooseMap = new HashMap<>();
    }

    public void notifyDataSetChanged(List<ShowTypeListGet.ShowTypeEntity> objects, int pos) {

        for(int i=0;i<objects.size();i++){

            if(i==pos){

                tabChooseMap.put(i, true);

            }else {

                tabChooseMap.put(i, false);

            }

        }

        notifyDataSetChanged();

    }

    @Override
    public RushedHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View convertView = LayoutInflater.from(context).inflate(R.layout.item_show_tab_list, null);

        return new RushedHolder(convertView);
    }

    @Override
    public void onBindViewHolder(RushedHolder holder, final int position) {

        if(tabChooseMap.get(position)){

            holder.item_show_tab_tv.setTextColor(ContextCompat.getColor(context, R.color.theme_color));

        }else{

            holder.item_show_tab_tv.setTextColor(ContextCompat.getColor(context, R.color.text_color));

        }

        holder.item_show_tab_tv.setText(list.get(position).title);

        holder.item_show_tab_ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                onItemClickListener.onItemClick(position);

            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public interface OnItemClickListener{
        void onItemClick(int pos);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        this.onItemClickListener = onItemClickListener;
    }

    class RushedHolder extends RecyclerView.ViewHolder{
        private TextView item_show_tab_tv;
        private LinearLayout item_show_tab_ll;

        public RushedHolder(View itemView) {
            super(itemView);
            ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) itemView);

            item_show_tab_ll = (LinearLayout) itemView.findViewById(R.id.item_show_tab_ll);
            item_show_tab_tv = (TextView) itemView.findViewById(R.id.item_show_tab_tv);

        }
    }
}
